package IOStream.IOStreamDome;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * ClassName:IOStream004
 * Package:IOStream.IOStreamDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/28-21:27
 * @Version:v1.0
 */
public class IOStream004 {
    public static void main(String[] args) {
        /*JDK7：IO流捕获异常的方法
         *
         * try后面的小括号中写创建对象的代码
         * 注意：只有实现AutoCloseable接口的类才能在小括号中创建对象
         *
         * try(){
         * }catch(){
         * }*/


        try (FileInputStream fis = new FileInputStream("E:\\aaa\\a.txt");
             FileOutputStream fos = new FileOutputStream("E:\\aaa\\ccc\\copy.txt");) {
            //拷贝
            int len;
            byte[] bytes = new byte[1024 * 1024 * 5];//5兆大小的数组
            while ((len = fis.read()) != -1) {
                fos.write(bytes, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
//        //释放资源
//        fos.close();
//        fis.close();

    }
}
